package com.yhq.basic.design.mediator;

/**
 * @author hqyin
 * @date 2023/2/2 6:31 下午
 */
public class ConcreteMediator extends Mediator {
    private Alarm alarm;
    private Calendar calendar;
    private Sprinkler sprinkler;
    private CoffeePot coffeePot;

    public ConcreteMediator(Alarm alarm, Calendar calendar, Sprinkler sprinkler, CoffeePot coffeePot) {
        this.alarm = alarm;
        this.calendar = calendar;
        this.sprinkler = sprinkler;
        this.coffeePot = coffeePot;
    }

    @Override
    public void doEvent(String eventType) {
        switch (eventType) {
            case "alarm":
                doAlarmEvent();
                break;
            case "calendar":
                calendar.doEvent();
                break;
            case "sprinkler":
                sprinkler.doEvent();
                break;
            default:
                coffeePot.doEvent();
        }
    }

    private void doAlarmEvent() {
        alarm.doEvent();
        coffeePot.doEvent();
        calendar.doEvent();
        sprinkler.doEvent();
    }
}
